package com.ldu.houserent.controller.backend;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ldu.houserent.common.base.BaseController;
import com.ldu.houserent.common.enums.OrderStatusEnum;
import com.ldu.houserent.common.util.PageUtil;
import com.ldu.houserent.entity.Order;
import com.ldu.houserent.service.HouseService;
import com.ldu.houserent.service.OrderService;
import com.ldu.houserent.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 我的租赁 的控制器
 */
@Controller("backHomeController")
public class HomeController extends BaseController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private HouseService houseService;
    @Autowired
    private UserService userService;

    /*
        租客的房屋信息列表，我的租赁
     */
    @RequestMapping("/admin/home")
    public String home(@RequestParam(value = "page",defaultValue = "1")Long pageNumber, @RequestParam(value = "size",defaultValue = "6")Long pageSize, Model model){
        Page page= PageUtil.initMpPage(pageNumber,pageSize);
        Order condition = new Order();
        condition.setCustomerUserId(getLoginUserId());              //获取用户id
        condition.setStatus(OrderStatusEnum.NORMAL.getValue());     //生效中的房屋
        Page<Order> orderPage = orderService.findAll(page,condition);
        for (Order order:orderPage.getRecords()){   //遍历当前页面的每一项
            order.setHouse(houseService.get(order.getHouseId()));
            order.setOwnerUser(userService.get(order.getOwnerUserId()));
        }
        model.addAttribute("pageInfo",orderPage);
        model.addAttribute("tab","home");         //鼠标点击后，改变页面中的字体颜色样式
        model.addAttribute("pagePrefix","/admin/home?");       //实现翻页
        return "admin/my-home";
    }//home

}









